/**
 * @param {number[]} nums
 * @return {number[]}
 */
var productExceptSelf = function (nums) {
  let cur = 1
  let n = nums.length
  let answer = new Array(n).fill(1)
  let dp1 = new Array(n).fill(1)
  let dp2 = new Array(n).fill(1)
  while (cur < n) {
    dp1[cur] = dp1[cur - 1] * nums[cur-1]
    cur++
  }
  cur = n - 2
  while (cur >= 0) {
    dp2[cur] = dp2[cur + 1] * nums[cur+1]
    cur--
  }
  for(let i=0;i<n;i++){
    answer[i] = dp1[i]*dp2[i]
  }
  return answer
}

console.log(productExceptSelf([1, 2, 3, 4]))
